/**
 * 
 */
package com.dsbridge.bank.model;

import java.sql.*;
import java.sql.DriverManager;

/**
 * @author Naveen
 * 
 */
public class DBUtils {
	static Connection con;
	// static block to load the driver one time
	static {
		try {
			// step1 load the driver
			Class.forName("com.mysql.jdbc.Driver");
		} catch (Exception e) {
			e.printStackTrace();
			System.out.println("Unable to load the driver");
		}
	}

	public static Connection getConnection() {
		// step 2:get the connection by passing url
		try {
			String url = "jdbc:mysql://localhost:3306/mydb";
			con = DriverManager.getConnection(url, "root", "naveen");
		} catch (Exception e) {
			System.out.println("Unablt to get the connection with database");
			e.printStackTrace();
		}
		return con;
	}

	public static void closeConnection() {
		try {
			// step 7:closing the connection
			con.close();
		} catch (Exception e) {
			System.out.println("failed to close the connection");
		}
}
	
}
